<?php 
    require_once ('../connect.php');
    //接受传递的参数
    $username = $_POST['username'];
    $password = $_POST['password'];
    $sex = $_POST['sex'];
    //新增用户
    $user_add_content = array(
        "username" => $username,
        "sex" => $sex,
        "flag" => 0
    );

    $check_sql = "select username from user where username='$username'";
    $check_result = $con->query($check_sql);
    $row = $check_result->fetch_assoc();

    if($row){
        $user_add_content['flag'] = 1;
        echo json_encode($user_add_content,JSON_UNESCAPED_UNICODE);
    }
    else{
        $sql = "insert into user(username,password,sex) values('$username','$password','$sex')";
        if($con->query($sql)){
            echo json_encode($user_add_content,JSON_UNESCAPED_UNICODE);
        }
        else{
            $user_add_content['flag'] = 2;
            echo json_encode($user_add_content,JSON_UNESCAPED_UNICODE);
        }
    }
?>
